<ui:composition template="/WEB-INF/templates/main-template.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="sidebar">
		<ui:include src="/WEB-INF/templates/public-sidebar.xhtml" />
	</ui:define>
	<ui:define name="content">
		<h:form>
			<p:growl></p:growl>
			<h:panelGrid style="width: 100%;">

				<h:outputText value="#{msg['roles.label.heading']}" styleClass="outputTextTitle" />
				<h:panelGrid columns="3" style="">
					<h:outputLabel value="Role " />
					<h:outputLabel value=":"/>
					<p:selectOneMenu value="#{rolesBean.selectedRoleId}" styleClass="adminSelectOneMenuWidth">
						<f:selectItem itemLabel="Select a role" itemValue="" />
						<f:selectItems value="#{rolesBean.rolesMap}" />
						<p:ajax event="change" listener="#{rolesBean.roleChangeListener}"
							update="@form" />
					</p:selectOneMenu>
				</h:panelGrid>
				<h:outputLabel
					value="Details for #{rolesBean.selectedRole.displayName} role"
					styleClass="outputTextSubTitle"
					rendered="#{rolesBean.detailsForRole}" />
				<h:panelGrid columns="1" style="border: 1px solid #d9d9d9; width: 100%" rendered="#{rolesBean.detailsForRole}">
					<h:panelGrid columns="3"  cellspacing="10">
						<h:outputLabel value="Role Name " />
						<h:outputLabel value=" : " />
						<p:inplace>
							<p:inputText value="#{rolesBean.selectedRole.role}" />
						</p:inplace>

						<h:outputLabel value="Role Type " />
						<h:outputLabel value=" : " />

						<p:selectOneMenu value="#{rolesBean.selectedRole.roletype}">
							<f:selectItems value="#{rolesBean.roleTypes}" />
						</p:selectOneMenu>


						<h:outputLabel value="Display Name " />
						<h:outputLabel value=" : " />
						<p:inplace>
							<p:inputText value="#{rolesBean.selectedRole.displayName}" />
						</p:inplace>

						<h:outputLabel value="Description " />
						<h:outputLabel value=" : " />
						<p:inplace>
							<p:inputTextarea value="#{rolesBean.selectedRole.description}" />
						</p:inplace>
					</h:panelGrid>
					
					<p:dataTable id="servicesDataTable" value="#{rolesBean.services}" var="row"
						>
						<f:facet name="header">
						<h:outputLabel value="Services" />
						</f:facet>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Service Name" />
							</f:facet>
							<h:outputText value="#{row.serviceName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Display Name" />
							</f:facet>
							<h:outputText value="#{row.displayName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Description" />
							</f:facet>
							<h:outputText value="#{row.description}" />
						</p:column>
						<p:column style="width: 40px; text-align: center">
							<f:facet name="header">
								<h:outputText value="Assign" />
							</f:facet>
							<f:ajax render="servicesDataTable">
								<p:selectBooleanCheckbox value="#{row.checked}" />
							</f:ajax>
						</p:column>

					</p:dataTable>
					
					<p:dataTable id="servicegroupsDataTable" value="#{rolesBean.serviceGroups}" var="row">
						<f:facet name="header">
						<h:outputLabel value="Servicegroups" />
						</f:facet>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Service Group Name" />
							</f:facet>
							<h:outputText value="#{row.servicegroupName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Display Name" />
							</f:facet>
							<h:outputText value="#{row.displayName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Description" />
							</f:facet>
							<h:outputText value="#{row.description}" />
						</p:column>
						<p:column style="text-align: center; width: 80px;" >
							<f:facet name="header">
								<h:outputText value="Services" />
							</f:facet>
							<h:outputText id="services" value="View Services" style="cursor: pointer; color: #888888" /> 
							<p:tooltip for="services">
								<p:dataList value="#{row.servicesList}" var="item" style="width: 100%; border: 1px solid red; " 
									type="unordered" itemType="none" >
									<p:column>
										#{item.displayName}
									</p:column>
								</p:dataList>
							</p:tooltip>
						</p:column>
						<p:column style="width: 40px; text-align: center">
							<f:facet name="header">
								<h:outputText value="Assign" />
							</f:facet>
							<f:ajax render="servicegroupsDataTable">
								<p:selectBooleanCheckbox value="#{row.checked}" />
							</f:ajax>
						</p:column>
					</p:dataTable>
					<!-- LEAVE TYPES ASSIGNED TO ROLE -->
					<p:dataTable id="roletypesDataTable" value="#{rolesBean.leavesTypes}" var="leaveType">
						<f:facet name="header">
						<h:outputLabel value="Leave Types" />
						</f:facet>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Leave Type Name" />
							</f:facet>
							<h:outputText value="#{leaveType.leaveType}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Display Name" />
							</f:facet>
							<h:outputText value="#{leaveType.displayname}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Description" />
							</f:facet>
							<h:outputText value="#{leaveType.description}" />
						</p:column>
						<p:column style="width: 40px; text-align: center">
							<f:facet name="header">
								<h:outputText value="Assign" />
							</f:facet>
							<f:ajax render="roletypesDataTable">
								<p:selectBooleanCheckbox value="#{leaveType.checked}" />
							</f:ajax>
						</p:column>
					</p:dataTable>
                   <!-- LEAVE TYPES ASSIGNED TO ROLE CLOSED HERE-->
					<p:commandButton value="Save"
						action="#{rolesBean.updateRoleAction}" update="@form" />
				</h:panelGrid>
			</h:panelGrid>
		</h:form>
	</ui:define>
</ui:composition>

